﻿Imports System.Xml

Public Class Frmconfig
    Private Sub txt_cmd_Click(sender As Object, e As EventArgs) Handles txt_cmd.Click
        Dim sServer As String = txt_server.Text
        ' 生成完整的 ServerUrl
        Dim sServerUrl As String = $"{txt_server.Text}/{txt_serverurl.Text}"'txt_serverurl.Text

        Dim sUpdateZipFile As String =$"{txt_server.Text}/{txt_updatezipfile.Text}" 'txt_updatezipfile.Text
        Dim sAppName As String = txt_appname.Text
        Dim sOpenApp As String = txt_openapp.Text

  

        ' 写入到配置文件
        SaveConfig(sServerUrl, sUpdateZipFile, sAppName, sOpenApp)

        ' 提示用户保存成功
        MessageBox.Show("配置已保存！")
        Me.DialogResult = DialogResult.OK ' 配置保存后关闭窗体
        end
    End Sub
 

    ' 保存配置到 AutoUpdate.config
    Private Sub SaveConfig(sServerUrl As String, sUpdateZipFile As String, sAppName As String, sOpenApp As String)
        Dim sConfigPath As String = "AutoUpdater.config"

        ' 创建或覆盖配置文件
        Dim xmlDoc As New XmlDocument()
        Dim root As XmlElement = xmlDoc.CreateElement("AutoUpdaterConfig")

        ' 创建并设置元素
        Dim serverUrlElement As XmlElement = xmlDoc.CreateElement("ServerUrl")
        serverUrlElement.InnerText = sServerUrl
        root.AppendChild(serverUrlElement)

        Dim updateZipFileElement As XmlElement = xmlDoc.CreateElement("UpdateZipFile")
        updateZipFileElement.InnerText = sUpdateZipFile
        root.AppendChild(updateZipFileElement)

        Dim appNameElement As XmlElement = xmlDoc.CreateElement("AppName")
        appNameElement.InnerText = sAppName
        root.AppendChild(appNameElement)

        Dim openAppElement As XmlElement = xmlDoc.CreateElement("OpenApp")
        openAppElement.InnerText = sOpenApp
        root.AppendChild(openAppElement)

        Dim AppFromElement As XmlElement = xmlDoc.CreateElement("AppFrom")
        AppFromElement.InnerText = ""
        root.AppendChild(AppFromElement)
        ' 将根元素添加到文档并保存
        xmlDoc.AppendChild(root)
        xmlDoc.Save(sConfigPath)
    End Sub
End Class